/*
 * @Author: yan_hai_dong 891236760@qq.com
 * @Date: 2022-10-25 10:36:51
 * @LastEditors: yan_hai_dong 891236760@qq.com
 * @LastEditTime: 2022-10-25 11:51:17
 * @FilePath: \uni-vue3-vite\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import path from 'path';
import fs from 'fs-extra';
import {
  defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
// import inject from '@rollup/plugin-inject';

function copyFile() {
  return {
    enforce: 'post',
    async writeBundle() {
      await fs.copy(
        path.resolve(__dirname, 'images'),
        path.join(
          __dirname,
          'unpackage/dist',
          process.env.NODE_ENV === 'production' ? 'build' : 'dev',
          process.env.UNI_PLATFORM,
          'images'
        )
      );
    },
  };
}

// const mpStoragePath = path.resolve(__dirname, './js_sdk/mp-storage/mp-storage');

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
    copyFile(),
    // inject({
    //   localStorage: [mpStoragePath, 'localStorage'],
    //   'window.localStorage': [mpStoragePath, 'localStorage'],
    // }),
  ],
  css: {
    preprocessorOptions: {
      // 引入全局样式
      scss: {
        additionalData: `@import "./src/assets/styles/variable.scss";@import "./src/assets/styles/uni.scss";`,
        javascriptEnabled: true
      }
    }
  },
  define: {
    'process.env.VUE_APP_TEST': JSON.stringify('test'),
  },
  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
      },
    },
  },
})